<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@include file="/resource/common/taglib.jspf"%>
<%@include file="/resource/common/commonJs.jspf"%>
<%@include file="/resource/common/commonCss.jspf"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${SESSION_COMPANY}</title>
<link rel="stylesheet" href="resource/plugins/bootstrap/css/bootstrap.css" />
<script type="text/javascript" src="${ctx }/resource/plugins/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx }/resource/plugins/validate/additional-methods.min.js"></script>
<link rel="stylesheet" href="resource/plugins/validate/css/validate.css" type="text/css" media="screen" />
<script type="text/javascript" src="${ctx }/resource/plugins/validate/messages_zh.js"></script>
<script type="text/javascript" src="${ctx }/resource/js/jquery/jquery.showLoading.min.js"></script>
<link rel="stylesheet" href="${ctx }/resource/js/jquery/showLoading.css" type="text/css" media="screen" />

<script type="text/javascript">
var PATH = "${ctx}";
$(document).ready(function() {
	$("body").showLoading();
	
	$("#form1").validate({
		rules : {
			smtp : {
				required : true,
			},
			port : {
				digits : true
			},
			mailName : {
				email : true,
			},
			mailPassword : {
				
			}
		},
		messages : {
			smtp : {
				required : "必填项例如:smtp.qq.com",
			},
			port : {
				digits : "端口必须为整数"
			},
			mailName : {
				email : "发送邮箱地址不正确",
			},
			mailPassword : {
				required : "邮箱密码不能为空,没有就先随便写"
			},
		},
		errorElement : "em",
		errorClass : "validate_error",
		submitHandler: function(form) { //通过之后回调
			save();
		},
		invalidHandler: function(form, validator) {
			return false;
		}
	});
	
	
	$("#form2").validate({
		rules : {
			smsName : {
				required : true,
			},
			smsPassword : {
				required : true,
			}
		},
		messages : {
			smsName : {
				required : "短信名不能为空,没有就先随便写"
			},
			smsPassword : {
				required : "短信密码不能为空,没有就先随便写"
			}
		},
		errorElement : "em",
		errorClass : "validate_error",
		submitHandler: function(form) { //通过之后回调
			save2();
		},
		invalidHandler: function(form, validator) {
			return false;
		}
	});
	
	$("body").hideLoading();
});

function save() {
	//保存
	$("body").showLoading();
	var id = $("#id").val();
	var smtp = $("#smtp").val();
	var port = $("#port").val();
	var mailName = $("#mailName").val();
	var mailPassword = $("#mailPassword").val();
	$.post(PATH + "/saveSysEmailConfigJson.do", {
		id : id,
		smtp :smtp,
		port :port,
		mailName :mailName,
		mailPassword :mailPassword,
		async : false // 是否异步
	}, function(data) {
		if (data != null) {
			if (data.ret == 1) {
				Tips(4000, // 提示层显示的时间
				"信息保存成功", // 显示的消息
				300, // 滑动速度
				"success");
			} else {
				Tips(4000, // 提示层显示的时间
				"信息保存失败-->"+data.msg, // 显示的消息
				300, // 滑动速度
				"error");
			}
		}
		$("body").hideLoading();
	});
}
	function save2() {
		//保存
		$("body").showLoading();
		var msid = $("#msid").val();
		var smsName = $("#smsName").val();
		var smsPassword = $("#smsPassword").val();
		$.post(PATH + "/saveSysSmsConfigJson.do", {
			id : msid,
			smsName :smsName,
			smsPassword :smsPassword,
			async : false // 是否异步
		}, function(data) {
			if (data != null) {
				if (data.ret == 1) {
					Tips(4000, // 提示层显示的时间
					"信息保存成功", // 显示的消息
					300, // 滑动速度
					"success");
				} else {
					Tips(4000, // 提示层显示的时间
					"信息保存失败-->"+data.msg, // 显示的消息
					300, // 滑动速度
					"error");
				}
			}
			$("body").hideLoading();
		});
}
	
</script>
</head>
<body>
	<div id="body-wrapper">
		<div id="main-content">
			<div class="content-box">
				<div class="content-box-header">
					<h3 class="panel-title">
						<shiro:hasPermission name="SysModule:SYS_EDIT"><c:if test="${entity.id!=null}">编辑信息</c:if></shiro:hasPermission>
						<shiro:hasPermission name="SysModule:SYS_ADD"><c:if test="${entity.id==null}">新增信息</c:if></shiro:hasPermission>
					</h3>
					<div class="clear"></div>
				</div>
				<div class="content-box-content">
					<div class="tab-content default-tab" >
						<div class="row">
							<div class="col-md-6" >
								<div class="panel panel-primary">
		                           <div class="panel-heading">
		                               	<i class="fa fa-envelope"></i> 系统邮箱设置 
		                               	<div class="pull-right">
											<a href="javascript:void(0)"  style="color:white"> <i style="font-size: 20px" class="fa fa-cog fa-spin"></i> </a>
										</div>
		                           </div>
		                           <div class="panel-body">
		                           		<form:form id="form1" name="form1" method="post" class="form-horizontal" action="">
		                           			<div class="form-group">
												<label class="col-sm-2 control-label">邮箱服务器地址：<span style="color: red">*</span></label>
												<div class="col-sm-10">
													<input type="hidden" id="id" name="id" value="${entity.id }" /> 
													<input type="text" class="form-control input-sm" name="smtp" id="smtp"  value="${entity.smtp }" placeholder="邮箱服务器地址"/>
												</div>
											</div>
											<div class="form-group">
												<label class="col-sm-2 control-label">邮箱服务器端口：<span style="color: red">*</span></label>
												<div class="col-sm-10">
													<input type="text" class="form-control input-sm" name="port" id="port"  value="${entity.port }" placeholder="邮箱服务器端口"/>
												</div>
											</div>
											<div class="form-group">
												<label class="col-sm-2 control-label">发件邮箱地址：<span style="color: red">*</span></label>
												<div class="col-sm-10">
													<input type="text" class="form-control input-sm" name="mailName" id="mailName"  value="${entity.mailName }" placeholder="系统邮箱地址"/>
												</div>
											</div>
											<div class="form-group">
												<label class="col-sm-2 control-label">发件邮箱密码：<span style="color: red">*</span></label>
												<div class="col-sm-10">
													<input type="text" class="form-control input-sm" name="mailPassword" id="mailPassword"  value="${entity.mailPassword }" placeholder="系统邮箱密码"/>
												</div>
											</div>
											<shiro:hasPermission name="SysModule:SYS_ADD">
												<div class="form-group">
													<label class="col-sm-2 control-label"></label>
													<div class="col-sm-10">
														<input type="submit" value="提交" class="btn btn-primary" style="width: 100%; height: 50px;cursor: pointer" />
													</div>
												</div>
											</shiro:hasPermission>
		                           		</form:form>
		                           </div>
		                        </div>
	                        </div>
	                        
	                        <div class="col-md-6" >
								<div class="panel panel-primary">
		                           <div class="panel-heading">
		                               	<i class="fa fa-comment"></i> 企信通
		                               	<div class="pull-right">
											<a href="javascript:void(0)"  style="color:white"> <i style="font-size: 20px" class="fa fa-cog fa-spin"></i> </a>
										</div>
		                           </div>
		                           <div class="panel-body">
		                           		<form:form id="form2" name="form2" method="post" class="form-horizontal" action="">
		                           			<div class="form-group">
												<label class="col-sm-2 control-label">短信用户名：</label>
												<input type="hidden" id="msid" name="msid" value="${entity.id }" /> 
												<div class="col-sm-10">
													<input type="text" class="form-control input-sm" name="smsName" id="smsName"  value="${entity.smsName }"  placeholder="短信用户名"/>
												</div>
											</div>
											<div class="form-group">
												<label class="col-sm-2 control-label">短信密码：</label>
												<div class="col-sm-10">
													<input type="text" class="form-control input-sm" name="smsPassword" id="smsPassword"  value="${entity.smsPassword }" placeholder="短信密码" />
												</div>
											</div>
											<shiro:hasPermission name="SysModule:SYS_ADD">
												<div class="form-group">
													<label class="col-sm-2 control-label"></label>
													<div class="col-sm-10">
														<input type="submit" value="提交" class="btn btn-primary" style="width: 100%; height: 50px;cursor: pointer" />
													</div>
												</div>
											</shiro:hasPermission>
		                           		</form:form>
		                           </div>
		                        </div>
	                        </div>
                        </div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>

</html>
